<template>
	<view>
		<!-- <view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input v-model="searchValue" data-name="searchValue" name="searchValue" @focus="onChange" @blur="onSearch"
				 :adjust-position="false" placeholder="请输入小区编号" confirm-type="search"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-green shadow-blur round" @tap="onSearch">搜索</button>
			</view>
		</view> -->
		<!-- <view v-if="building.length>0"> -->
		<view>
			<view class="padding">楼栋信息</view>
			<view class="cu-list menu">
				<view class="cu-item" v-for="(unit, idx) in building" :key="idx" :label="unit.buildingCode">
					<view class="content padding-tb-sm" is-link @click="chooseFloot(unit)">
						<view>
							<text class="cuIcon-clothesfill text-blue margin-right-xs"></text> {{unit.buildingName}}</view>
						<view class="text-gray text-sm">
							<text class="cuIcon-infofill margin-right-xs"></text> {{unit.buildingCode}}</view>
					</view>
				</view>
			</view>
		</view>
<!-- 		<view v-else>
			<no-data-page></no-data-page>
		</view> -->
	</view>
</template>

<script>
	import context from '../../lib/java110/Java110Context.js';
	const constant = context.constant;
	import noDataPage from '@/components/no-data-page/no-data-page.vue'
	export default {
		data() {
			return {
				building:'',
				buildingName:'', // 小区名
				buildingNumId:'', //小区id
				appUserName: '',
				areaCode: '',
				searchValue: '',
				unitName: "",
				units: [],
				floorId:''
			}
		},
		components: {
			noDataPage
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			context.onLoad(options);
			this.loadUnit();
		},
		methods: {
			onSearch() {
				this.loadUnit();
			},

			// onClick() {
			// 	this.loadUnit();
			// },
			
			chooseFloot: function(_unit) {
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				uni.setStorageSync("_selectFloor", _unit);
				prevPage.buildingName = _unit.buildingName;
				wx.navigateBack({
					delta: 1
				});
			},
			loadUnit: function() {
				let _that = this;
				let fountInfor = uni.getStorageSync("_selectCommunity");
				if (fountInfor != null && fountInfor != undefined && fountInfor != '') {
					_that.plotCommunityId = fountInfor.id; //小区id
				}
				
				let dataObj = {
					page: 1,
					row: 15,
					// communityId:_that.plotCommunityId,
					// name: this.searchValue,
					// floorId: this.floorId
				};
				uni.request({
					url: constant.url.queryFloor,
					header: context.getHeaders(),
					POST: "GET",
					data: dataObj,
					//动态数据
					success: function(res) {
						console.log("666",res.data); //成功情况下跳转
			
						if (res.statusCode == 200) {
							let _units = res.data.result;
							// _that.units = _units;
							// console.log("楼栋",_that.units)
							
							for(let i = 0;i< _units.length;i++){
								_that.building = _units[i].children
							}
						}
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});
			}
		}
	}
</script>

<style>

</style>
